<?php
/**
*
* @author Blackpawn blackpawn666@hotmail.com - http://blackpawnsarchives.net
* @co_author GameCharmer admin@gamecharmer.com - http://gaming.gamecharmer.com
* @package Age of Dragons Mod :: ( Game Console Required )
* @version $Id: war.php 1.1.1 12-26-2009 Blackpawn
* @copyright (c) 2009 Blackpawns Archives
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/

define('GC_MOD', true);
define('IN_PHPBB', true);
define('AOD', true);

$phpbb_root_path =  '../../';
$templates_path = '../../../games/aod/templates/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/mods/game_console/gc_common.' . $phpEx);
include($phpbb_root_path . 'games/aod/common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Set custom language path
$user->set_custom_lang_path($phpbb_root_path.'games/aod/language/');

//load our language file
$user->add_lang('common');

// Now add the phpBB language path
$user->set_custom_lang_path($phpbb_root_path . 'language');

// Load the Game Console language file
$user->add_lang('mods/game_console');

if ($user->data['user_id'] == ANONYMOUS)
{
	login_box('', $user->lang['LOGIN']);
}

if ($user->data['is_bot'])
{
	redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
}

// Constants
$war_page = TRUE; 		// Highlights the war tab
$error_msgs = null;
$pagination_url = append_sid("war.$phpEx");
$admin = 0;

// Vars
$cmd = request_var('cmd','');
$qid = request_var('qid', 0);
$start = request_var('start', 0);

// AOD Config
$kingdoms_per_page = $aod_config['kingdoms_per_page'];


// Gather some user info
$user_id = $user->data['user_id'];
$account_status = check_account_status($user_id);
if ($account_status == FALSE)
{
	redirect(append_sid("{$phpbb_root_path}/games/index.$phpEx"));
}

// Fetch kingdom data
$king = fetch_kingdom_data($user_id);
$kingdom_status = $king['kingdom_status'];
$admin_access = $king['admin_access'];
$kingdom_sponsor = $king['kingdom_sponsor'];
$kingdom_level = $king['kingdom_level'];
$kingdom_net = $king['kingdom_net'];
$kingdom_land = $king['kingdom_land'];
$kingdom_food = $king['kingdom_food'];
$kingdom_wood = $king['kingdom_wood'];
$kingdom_iron = $king['kingdom_iron'];
$kingdom_gold = $king['kingdom_gold'];
$kingdom_stamina = $king['kingdom_stamina'];
$kingdom_turns = $king['kingdom_turns'];

// Check to see if this user is a admin staff member
if ($user_id == 2 || $admin_access == 1)
{
	$admin = 1;
}

// Check kingdom status to see if this account is frozen
if($kingdom_status == 1)
{
	// Lets make sure the main admin can't be blocked
	if ($user_id <> 2){
		trigger_error($user->lang['FROZEN'] . back_link());
	}
}


	// Build Quest List
	$total_kingoms = count_kingdoms();
	
	$sql = 'SELECT *
	FROM ' . AOD_KINGDOMS_TABLE . '      
	ORDER BY kingdom_net DESC';
	$result = $db->sql_query_limit($sql, $kingdoms_per_page, $start);
				
	while ($row = $db->sql_fetchrow($result))
	{
		$uid = $row['user_id'];
		$kname = $row['kingdom_name'];
		$kingdom_sponsor = $row['kingdom_sponsor'];
		$kingdom_status = $row['kingdom_status'];
		
		if($kingdom_sponsor)
		{
			$sponsor_sig = ' <img src="images/sponsor.png" alt="'.$user->lang['GAME_SPONSOR'].'" title="'.$user->lang['GAME_SPONSOR'].'" border="0">';
		}else{
			$sponsor_sig = '';
		}
		
		switch($kingdom_status)
		{
			case 1:
				$kingdom = '<a href="viewking.php?uid='.$uid.'" class="stextblue"<b>'.$kname.$sponsor_sig.'</b></a>';
			break;
			default:
				$kingdom = '<a href="viewking.php?uid='.$uid.'" class="stext"<b>'.$kname.$sponsor_sig.'</b></a>';
			break;
		}
		
		$klevel = $row['kingdom_level'];
		$kpop = $row['kingdom_pop'];
		$knet = $row['kingdom_net'];

		$template->assign_block_vars('kingdomrow', array(
			'NUM' 	=> 	number_format($i + ($start + 1)),
			'NAME'	=>	$kingdom,
			'LEVEL'	=>	number_format($klevel),
			'NET'	=>	number_format($knet),
			'POP'	=>	number_format($kpop),		
			)
		);
		++$i;	
	}	
	$db->sql_freeresult($result);

// Display an error messages to the user
if($error_msgs){
	$error_msgs = '<span class="errormsg"><b>'.$error_msgs.'</b></span>';
}

include($phpbb_root_path . 'games/aod/includes/page_header.' . $phpEx);


// Output page
page_header($game_name.' - '.$user->lang['WAR']);

$template->set_filenames(array(
	'body' => $templates_path.'war_body.html')
);

page_footer();
?>